package com.leetcode.p100;

import com.utils.DataUtils;

public class Test167 {

    public int[] twoSum(int[] numbers, int target) {
        int[] result = new int[2];

        int left = 0, right = numbers.length - 1;

        while (left < right) {
            int sum = numbers[left] + numbers[right];
            if (sum == target) {
                result[0] = left + 1;
                result[1] = right + 1;
                break;
            } else if (sum > target) {
                right--;
            } else {
                left++;
            }
        }
        return result;
    }

    public static void main(String[] args) {
        Test167 test153 = new Test167();
        int[] result = test153.twoSum(new int[]{1, 2, 4, 5, 6, 7}, 5);
        DataUtils.printArray(result);
    }

}
